package org.apache.servicecomb.samples.practise.houserush.sale.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Entity
@Table(name = "house_orders")
@EntityListeners(AuditingEntityListener.class)
public class HouseOrder {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @ManyToOne
    @JoinColumn(name = "sale_id")
    private Sale sale;

    //房源订单和房源订单收藏是一对多的关系
    @OneToMany(mappedBy = "houseOrder")
    @Fetch(FetchMode.JOIN)
    @JsonIgnoreProperties(ignoreUnknown = true, value = {"houseOrder"})
    private List<Favorite> favoriteList = new ArrayList<>();

    //可以按照客户id进行查询，表明该房源订单有没有被客户收藏
    @Transient
    private String favorite;

    private Integer customerId;
    private Integer houseId;
    private String state = "new";
    @Temporal(TemporalType.TIMESTAMP)
    private Date orderedAt;
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedAt;


    //房源名称
    @Transient
    private String houseName;
    //房源价格
    @Transient
    private BigDecimal price;
    //楼栋名称
    @Transient
    private String builDingName;
    //楼盘名称
    @Transient
    private String realestateName;
    //用户名称
    @Transient
    private String name;
    //用户电话
    @Transient
    private String phone;

    @Override
    public String toString() {
        return "HouseOrder{" +
                "id=" + id +
                ", sale=" + sale +
                ", favoriteList=" + favoriteList +
                ", favorite='" + favorite + '\'' +
                ", customerId=" + customerId +
                ", houseId=" + houseId +
                ", state='" + state + '\'' +
                ", orderedAt=" + orderedAt +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                ", houseName='" + houseName + '\'' +
                ", price=" + price +
                ", builDingName='" + builDingName + '\'' +
                ", realestateName='" + realestateName + '\'' +
                ", name='" + name + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }
}
